home *** CD-ROM | disk | FTP | other *** search
-
- static char RCSId[]="$Id: SubCell.m,v 1.1.1.1 1993/03/18 03:36:07 davis Exp $";
-
-
- /*
- * Based on CustomCell in the NeXT Developer Example ScrollDoodScroll
- * by Jayson Adams.
- */
-
- #import <appkit/Font.h>
- #import <appkit/NXImage.h>
- #import <appkit/Text.h> /* NXTextFontInfo() */
-
- #import <dpsclient/wraps.h>
-
- #import "SubCell.h"
- #import "SubObject.h"
-
-
- #define FIRST_COLUMN_START 4.0
- #define TEXT_COLUMN_START 20.0
-
-
- @implementation SubCell
-
- static id attachmentImage = 0;
- static NXSize imageSize;
-
- - init
- {
- [super init];
-
- /* get the "attachment" image */
- if (!attachmentImage) {
- attachmentImage = [NXImage findImageNamed:"Attachment"];
- [attachmentImage getSize:&imageSize];
- }
-
- [self setStringValue:""];
- return self;
- }
-
-
- /*
- * Every SubCell is associated with a SubObject which stores the
- * information that the SubCell displays. When the SubObject is set,
- * we set our instance variables to match it.
- */
- - setSubObject:anObject
- {
- const char *aString;
-
- if (anObject) {
- subObject = anObject;
- aString = [subObject stringValue];
- [self setStringValue: aString? aString: ""];
- showAttachment = [subObject isAttachment];
-
- return self;
- } else
- return nil;
- }
-
-
- - subObject
- {
- return subObject;
- }
-
-
- - setFont:fontObj
- {
- [super setFont:fontObj];
- /*
- * Save this info so we don't have to look it up every time we
- * draw. Note: "support" for a TextFieldCell is a font object.
- */
- NXTextFontInfo(support, &ascender, &descender, &lineHeight);
-
- return self;
- }
-
-
-
- - drawInside:(const NXRect *)cellFrame inView:controlView
- {
- NXPoint imageOrigin;
- NXRect rectArray[2];
-
- /* Set the font according to our drawing status. */
- if (NXDrawingStatus != NX_DRAWING) {
- [support set];
- } else {
- [[support screenFont] set];
- }
-
- /* Erase the cell. */
- PSsetgray((cFlags1.state || cFlags1.highlighted) ? NX_WHITE : NX_LTGRAY);
- NXRectFill(cellFrame);
-
- /* Draw the "attachment" image, if the SubObject wants us to. */
- if (showAttachment) {
- imageOrigin.x = FIRST_COLUMN_START;
- imageOrigin.y = NX_Y(cellFrame) + NX_HEIGHT(cellFrame) - 1
- - (NX_HEIGHT(cellFrame) - imageSize.height) / 2.0;
- [attachmentImage composite:NX_PLUSD toPoint:&imageOrigin];
- }
-
- /* Draw the text. */
- PSsetgray(NX_BLACK);
- PSmoveto(NX_X(cellFrame) + TEXT_COLUMN_START,
- NX_Y(cellFrame) + lineHeight - descender);
- PSshow(contents);
-
- /* Draw the two dark gray lines above and below the cell. */
- PSsetgray(NX_DKGRAY);
- if (cFlags1.state || cFlags1.highlighted) {
- /*
- * Draw 1-pixel-high rectangles instead of lines (this is
- * faster than PSmoveto(); PSlineto()).
- */
- NXSetRect(&(rectArray[0]), NX_X(cellFrame), NX_Y(cellFrame),
- NX_WIDTH(cellFrame), 1.0);
- NXSetRect(&(rectArray[1]), NX_X(cellFrame), NX_MAXY(cellFrame) - 1.0,
- NX_WIDTH(cellFrame), 1.0);
-
- /*
- * Using NXRectFillList is faster than separate calls to
- * NXRectFill.
- */
- NXRectFillList(rectArray, 2);
- }
-
- return self;
- }
-
-
-
- // Shuts up the compiler about unused RCSId
- - (const char *) rcsid
- {
- return RCSId;
- }
-
-
- @end
-